Release 10.1A: OpenEdge Development:
Programming Interfaces
Passing arrays as parameters
This section describes how you can pass arrays as parameters to and from DLL functions.
Note: You cannot pass an array of indeterminate extent to a DLL.INTEGER and DECIMAL arrays
When a DLL Function requires an array of type
BYTE,SHORT,UNSIGNED-SHORT,INT,LONG,FLOAT, orDOUBLE, you can pass an array of the appropriate Progress type (INTEGERorDECIMAL) as a parameter. You can use any parameter mode (INPUT,INPUT-OUTPUT, orOUTPUT). For the data type in the prototype, you can use just the type (for example,LONG) or you can specify it with theHANDLETOoption (for example,HANDLETO). Progress always passes the array of values as a pointer so theHANDLETOoption is redundant, as it is with anyINPUT-OUTPUTorOUTPUTparameter.Here is an example C Code Prototype for a function called updateCounts:
Here is the equivalent Progress 4GL Prototype for the updateCounts procedure.
Here is the 4GL statement that executes the updateCounts procedure:
CHARACTER and LONGCHAR arrays
If the DLL requires an array of strings as
INPUTwhich is represented by an array of pointers to strings, you can pass a ProgressCHARACTERorLONGCHARarray. You can do the same if it is anINPUT-OUTPUTparameter, however, this is not recommended. If the DLL updates the data such that the output string is longer than the input string, this can result in a memory exception or other unpredictable behavior. Therefore, forINPUT-OUTPUTparameters you should use aMEMPTRarray, described in the "MEMPTR arrays" section.Also, just as you cannot pass
CHARACTERorLONGCHAROUTPUTparameters to a DLL, you also cannot pass aCHARACTERorLONGCHARarray as anOUTPUTparameter. If the DLL requires an array of character buffers that it will modify or if the DLL allocates memory for a set of strings and returns them as an array of pointers, you should use aMEMPTRparameter.As with the
INTEGERandDECIMALtypes of arrays, the data type in the prototype can be either just the type (for example,CHARACTER) or you can specify it with theHANDLETOoption.Here is an example C Code Prototype for a function called
nameLookup:
Here is the equivalent Progress 4GL Prototype for the
nameLookupprocedure:
Here is the 4GL statement that executes the
nameLookupprocedure:
MEMPTR arrays
If the DLL requires an array of pointers, where each pointer either points at a string or a structure, you can pass a Progress
MEMPTRarray. ForINPUTorINPUT-OUTPUTparameters, you initialize eachMEMPTRas appropriate to contain the string or structure to pass forINPUT. If it is anINPUT-OUTPUTparameter, you must insure that the allocated size (that is, the size set bySET-SIZE) is large enough to hold any expected output value, not just large enough to hold the input value. For anOUTPUTparameter, if the DLL expects an array of pointers to allocated buffers, you must useSET-SIZEto the required size for eachMEMPTRin the array. If the DLL allocates memory for a set of strings or structures and returns them as an array of pointers, you must set eachMEMPTRto at least the size of a pointer (for example, 4 or 8 bytes depending on the platform). You then use theGET-POINTER-VALUEandSET-POINTER-VALUEfunctions to access the data on return. (For more information on theGET-andSET-POINTER-VALUEfunctions, see OpenEdge Development: Progress 4GL Reference .) If you want to passNULLas one or more of the pointers, the correspondingMEMPTRin the array can be a nullMEMPTR, meaning that it is either uninitialized or you did aSET-SIZEon it to set it to zero length. For information on passing aMEMPTRparameter, see the "Using MEMPTR variables as parameters" section.Here is an example C Code Prototype for a function called
getNames:
Here is the equivalent Progress 4GL Prototype for the
getNamesprocedure. In this case, the DLL does not allocate the buffer, but expects to be passed an array of buffer pointers:
Here is the 4GL statement that executes the
getNamesprocedure:
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |